/*
  学习目标：动态路由
*/

import React, { Component } from 'react';
import { Redirect, Switch, Route, Link, NavLink, BrowserRouter as Router } from 'react-router-dom';
import './index.css';

export default class App extends Component {
  render() {
    return (
      <Router>
        <NavLink to="/home" activeClassName="xxx-xx" exact>
          首页
        </NavLink>
        <br />
        <Link to="/my">我的音乐</Link>
        <br />
        <Link to="/friend">发现</Link>

        <Switch>
          <Redirect from="/" to="/home" exact></Redirect>
          <Route path="/home" component={Home} exact></Route>
          {/* 💥 注意: url为/my时, 无法匹配动态路由 */}
          {/* 1. path改造为动态路由 */}
          <Route path="/my/:xxx" component={MyMusic}></Route>

          <Route component={NotFound}></Route>
        </Switch>
      </Router>
    );
  }
}

function NotFound() {
  return <h3>404页面</h3>;
}

function Home() {
  return <h1>我是首页组件</h1>;
}

function MyMusic(props) {
  // 2. 通过props.match.params接收动态路由数据
  console.log('props.params  ----->  ', props.match.params.xxx);
  return <h1>我是我的音乐件</h1>;
}
